#include "Ammo.h"
#include "ObjectDatabase.h"
#include "Util.h"
#include "Game.h"
#include "Renderer.h"

Ammo::Ammo(AmmoType type, int num) : Item(GT_IT_AMMO) {
	m_types[TH_AMMO_TYPE] = type;
	const AmmoInfo& info = g_objectDatabase->getAmmoInfo(type);
	m_weight = info.weight;
	m_stackable = true;
	m_numStacked = num;
}

Ammo::Ammo(std::ifstream& file) : Item(GT_IT_AMMO, file) {
	int* tokens = Util::intSplit(file);
	m_types[TH_AMMO_TYPE] = tokens[0];
	const AmmoInfo& info = g_objectDatabase->getAmmoInfo(AmmoType(tokens[0]));
	m_weight = info.weight;
	m_stackable = true;
	delete[] tokens;
}

Ammo::~Ammo() {
}

void Ammo::save(std::ofstream& file) const {
	file << getType(TH_GENERIC_TYPE) << "\n";
	Item::save(file);
	file << getType(TH_AMMO_TYPE) << "\n";
}

void Ammo::render(float x, float y) {
	g_renderer->render(*this, x, y);
}